package com.ruirenyun.util.font;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.awt.*;
import java.io.InputStream;

/**
 * @author Deng Ye
 * @version 1.0
 * @description
 * @date 2021/4/9 19:08
 */
public class LoadFontUtil {
    public static Font loadFont(float fontSize) {
        try {
            Resource res = new ClassPathResource("SourceHanSansCN-Regular.ttf");

            InputStream aixing = res.getInputStream();

            Font dynamicFont = Font.createFont(Font.TRUETYPE_FONT, aixing);

            Font dynamicFontPt = dynamicFont.deriveFont(fontSize);

            aixing.close();

            return dynamicFontPt;

        } catch (Exception e) {
            e.printStackTrace();
            return new Font("宋体", Font.PLAIN, 14);
        }

    }


}
